package cn.db101.kaoqinserver.controller;

import cn.db101.kaoqinserver.config.ApiResult;
import cn.db101.kaoqinserver.domain.Check;
import cn.db101.kaoqinserver.domain.User;
import cn.db101.kaoqinserver.enumration.CheckStatus;
import cn.db101.kaoqinserver.enumration.CheckType;
import cn.db101.kaoqinserver.model.request.CheckParam;
import cn.db101.kaoqinserver.model.request.ClassesParam;
import cn.db101.kaoqinserver.model.request.CourseParam;
import cn.db101.kaoqinserver.service.CheckService;
import cn.db101.kaoqinserver.service.ClassesService;
import cn.db101.kaoqinserver.service.UserService;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
@RequestMapping("v1/kaoqin/check")
public class CheckController {

    @Autowired
    private CheckService checkService;

    @PostMapping("leaveSave")
    public ApiResult<?> leaveSave(@RequestBody Check check) {

        checkService.save(check);
        return ApiResult.ofSuccess();

    }

    /**
     * 直接签到
     */
    @PostMapping("directSave")
    public ApiResult<?> directSave(@RequestBody Check check) {

        check.setCheckType(CheckType.DIRECT.getCheckType());
        checkService.thirdSave(check);
        return ApiResult.ofSuccess();

    }

    /**
     * 位置签到
     */
    @PostMapping("locationSave")
    public ApiResult<?> locationSave(@RequestBody Check check) {

        check.setCheckType(CheckType.LOCATION.getCheckType());
        checkService.thirdSave(check);
        return ApiResult.ofSuccess();

    }

    @PostMapping("qrcodeSave")
    public ApiResult<?> qrcodeSave(@RequestBody Check check) {

        check.setCheckType(CheckType.QRCODE.getCheckType());
        checkService.thirdSave(check);
        return ApiResult.ofSuccess();

    }

    @PostMapping("gestureSave")
    public ApiResult<?> gestureSave(@RequestBody Check check) {

        check.setCheckType(CheckType.HANDWRITE.getCheckType());
        checkService.thirdSave(check);
        return ApiResult.ofSuccess();

    }

    @PostMapping("record/page")
    public ApiResult<?> recordPage(@RequestBody CheckParam checkParam) {

        return ApiResult.ofSuccess(checkService.page(checkParam));
    }

    @PostMapping("remove")
    public ApiResult<?> remove(@RequestBody Check check) {

        checkService.removeById(check);
        return ApiResult.ofSuccess();
    }

    @PostMapping("changeStatus")
    public ApiResult<?> changeStatus(@RequestBody Check check) {

        checkService.changeStatus(check);
        return ApiResult.ofSuccess();
    }

}
